﻿namespace YunQue.Gateway
{
    public class ServiceLevelMiddleware
    {
        private readonly RequestDelegate _next;

        public ServiceLevelMiddleware(RequestDelegate next)
        {
            _next = next;
        }

        public async Task Invoke(HttpContext context)
        {
            //从请求中获取tenantCod,再根据tenantCod获取企业所在的站点信息  w  ww  www
            var tenantCode = context.Request.Headers["Token"].ToString();
            //这里需要根据tenantCode获取站点信息，就先随机一个了
            var num = new Random().Next(0, 3);
            var level = num == 0 ? "www" : num == 1 ? "ww" : "w";
            // 修改请求的目标地址
            context.Request.Path = $"/{level}" + context.Request.Path;
            await _next(context);
        }
    }
}
